import { cityProMatch, cascaderProvinceCity } from '/@/utils/adcode';
import { FormSchema } from '/@/components/Form/index';

export const columns = [
  {
    title: '登录名',
    dataIndex: 'username',
  },
  {
    title: '客户名',
    dataIndex: 'customer',
  },
  {
    title: '客户负责人',
    dataIndex: 'accountManager',
  },
  {
    title: '联系方式',
    dataIndex: 'contact',
  },
  {
    title: '地区',
    dataIndex: 'area',
    // ormat: (text: string, record: Recordable, index: number) => {
    format: (text: string, record: Recordable, index: number) => {
      return `${record.province ? cityProMatch[record.province].name : ''}${
        record.city
          ? cityProMatch[record.province].children.find((ele) => ele.value == record.city).label
          : ''
      }`;
    },
  },
  {
    title: '角色',
    dataIndex: 'clientType',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
  },
];

export const listFormSchema: FormSchema[] = [
  {
    field: 'basc',
    label: '基本信息',
    component: 'Divider',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'id',
    label: '编码',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'username',
    label: '登录名',
    component: 'Input',
    rules: [
      {
        required: true,
        message: '请输入登录名',
      },
    ],
    dynamicDisabled(renderCallbackParams) {
      return renderCallbackParams.model?.id;
    },
  },
  {
    field: 'password',
    label: '密码',
    component: 'InputPassword',
    componentProps: {
      autocomplete: 'new-password',
    },
    ifShow(renderCallbackParams) {
      return !renderCallbackParams.model?.id;
    },
    rules: [
      {
        required: true,
        message: '请输入密码',
      },
    ],
  },
  {
    field: 'customer',
    label: '客户名',
    component: 'Input',
    rules: [
      {
        required: true,
        message: '请输入客户名',
      },
    ],
  },
  {
    field: 'accountManager',
    label: '客户负责人',
    component: 'Input',
    rules: [
      {
        required: true,
        message: '请输入客户负责人',
      },
    ],
  },
  {
    field: 'contact',
    label: '联系方式',
    component: 'Input',
    rules: [
      {
        required: true,
        message: '请输入联系方式',
      },
    ],
  },
  {
    field: 'area',
    label: '地区',
    component: 'Cascader',
    rules: [
      {
        required: true,
        // 规则验证改写
        validator: async (rule, value) => {
          if (value?.length === 2) {
            return Promise.resolve();
          } else {
            return Promise.reject('请选择地区');
          }
        },
        trigger: 'change',
      },
    ],
    componentProps: {
      options: cascaderProvinceCity,
    },
  },
  {
    field: 'detailedAddress',
    label: '详细地址',
    component: 'Input',
    rules: [
      {
        required: true,
        message: '请输入详细地址',
      },
    ],
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: '登录名',
    component: 'Input',
    componentProps: {
      placeholder: '请输入登录名',
    },
    colProps: {
      xl: 12,
      xxl: 6,
    },
    // 动态判断当前组件是否禁用
    // dynamicDisabled(renderCallbackParams) {
    //   return renderCallbackParams.model?.id;
    // },
  },
  {
    field: 'customer',
    label: '客户名',
    component: 'Input',
    componentProps: {
      placeholder: '请输入客户名',
    },
    colProps: {
      xl: 12,
      xxl: 6,
    },
  },
];

export const data = [
  {
    id: 35,
    username: 'userchuangli',
    password: null,
    customer: 'chuangli',
    clientType: 'CUSTOMER',
    createTime: '2024-05-09 14:48:41',
    updateTime: '2024-05-09 06:48:47',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '130000',
    city: '130500',
    accountManager: '一',
    contact: '12312312312',
    detailedAddress: '海悦大街',
    enterprise: false,
  },
  {
    id: 34,
    username: 'lxl',
    password: null,
    customer: 'lxl',
    clientType: 'ENTERPRISE',
    createTime: '2024-02-05 14:17:22',
    updateTime: '2024-02-05 14:46:42',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '140000',
    city: '140300',
    accountManager: '123',
    contact: '11111111111',
    detailedAddress: 'lxl',
    enterprise: true,
  },
  {
    id: 31,
    username: 'shiwei1',
    password: null,
    customer: 'sw',
    clientType: 'CUSTOMER',
    createTime: '2024-01-29 09:24:55',
    updateTime: '2024-02-05 08:37:41',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '110000',
    city: '110000',
    accountManager: 'w',
    contact: '19322932321',
    detailedAddress: '1sadasda',
    enterprise: false,
  },
  {
    id: 30,
    username: 'chuangli',
    password: null,
    customer: 'chuangli',
    clientType: 'CUSTOMER',
    createTime: '2023-11-28 14:30:26',
    updateTime: '2023-11-28 14:30:27',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '130000',
    city: '130100',
    accountManager: 'tim',
    contact: '12312312301',
    detailedAddress: '创力',
    enterprise: false,
  },
  {
    id: 29,
    username: 'wangwei',
    password: null,
    customer: 'wangwei',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-02 16:09:38',
    updateTime: '2024-02-04 16:19:38',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '150000',
    city: '150500',
    accountManager: 'wangwei',
    contact: '2134124',
    detailedAddress: 'dfad',
    enterprise: true,
  },
  {
    id: 27,
    username: 'sssssss',
    password: null,
    customer: 'dasdadssss',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-02 11:13:34',
    updateTime: '2023-11-02 15:02:16',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '210000',
    city: '210800',
    accountManager: 'dsadasd',
    contact: 'dsadasda',
    detailedAddress: 'dsadasdasd',
    enterprise: true,
  },
  {
    id: 26,
    username: 'dadad',
    password: null,
    customer: 'dasda',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-02 11:02:07',
    updateTime: '2023-11-02 11:02:07',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '140000',
    city: '140300',
    accountManager: 'dasdasd',
    contact: 'asdasd',
    detailedAddress: 'dasdasd',
    enterprise: true,
  },
  {
    id: 25,
    username: 'dadsdas',
    password: null,
    customer: 'dasdasd',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-02 10:13:07',
    updateTime: '2023-11-02 10:13:08',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '140000',
    city: '140400',
    accountManager: 'asdasdasd',
    contact: 'asdasd',
    detailedAddress: 'dasdasdasd',
    enterprise: true,
  },
  {
    id: 24,
    username: 'lisi',
    password: null,
    customer: 'LI',
    clientType: 'CUSTOMER',
    createTime: '2023-11-02 09:25:28',
    updateTime: '2023-11-02 09:44:25',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '150000',
    city: '150500',
    accountManager: '改客户负责人',
    contact: '10987654321',
    detailedAddress: '亮马桥',
    enterprise: false,
  },
  {
    id: 15,
    username: 'shiwei',
    password: null,
    customer: '石伟',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-01 17:14:31',
    updateTime: '2023-11-02 09:10:53',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '130000',
    city: '130600',
    accountManager: '石伟123',
    contact: '17600608660',
    detailedAddress: 'asdasd',
    enterprise: true,
  },
  {
    id: 14,
    username: 'zhangsan',
    password: null,
    customer: 'ZHANG',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-01 10:47:09',
    updateTime: '2023-11-02 15:02:45',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '150000',
    city: '150900',
    accountManager: '改客户负责人',
    contact: '10987654321',
    detailedAddress: '1233333',
    enterprise: true,
  },
  {
    id: 11,
    username: 'admin',
    password: null,
    customer: '创力科技',
    clientType: 'ENTERPRISE',
    createTime: '2023-10-13 09:21:40',
    updateTime: '2023-10-27 15:25:11',
    token: null,
    pageNum: null,
    pageSize: null,
    province: null,
    city: null,
    accountManager: null,
    contact: null,
    detailedAddress: null,
    enterprise: true,
  },
  {
    id: 10,
    username: 'yzm',
    password: null,
    customer: 'YZM',
    clientType: 'ENTERPRISE',
    createTime: '2023-10-09 16:14:24',
    updateTime: '2023-10-12 17:03:39',
    token: null,
    pageNum: null,
    pageSize: null,
    province: null,
    city: null,
    accountManager: null,
    contact: null,
    detailedAddress: null,
    enterprise: true,
  },
  {
    id: 9,
    username: 'mm',
    password: null,
    customer: 'YZM',
    clientType: 'CUSTOMER',
    createTime: '2023-10-09 16:02:22',
    updateTime: '2023-10-12 17:03:23',
    token: null,
    pageNum: null,
    pageSize: null,
    province: null,
    city: null,
    accountManager: null,
    contact: null,
    detailedAddress: null,
    enterprise: false,
  },
  {
    id: 4,
    username: 'sunpeihua',
    password: null,
    customer: 'SPH',
    clientType: 'CUSTOMER',
    createTime: '2023-10-08 11:13:10',
    updateTime: '2023-10-12 17:03:17',
    token: null,
    pageNum: null,
    pageSize: null,
    province: null,
    city: null,
    accountManager: null,
    contact: null,
    detailedAddress: null,
    enterprise: false,
  },
];
